package com.decelo.jpa.cacheCofig;

import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.event.CacheManagerEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 缓存log输出，监控
 * @author :JronZhang Create_Time:2018-12-31 1:21
 */
public class cacheManagerEventListenDemo implements CacheManagerEventListener {
    private Logger logger= LoggerFactory.getLogger(this.getClass());

    private final CacheManager cacheManager;

    public cacheManagerEventListenDemo(CacheManager cacheManager) {
        this.cacheManager = cacheManager;
    }


    @Override
    public void init() throws CacheException {
        //缓存初始化 ....
        logger.info("缓存初始化 ....");
    }

    @Override
    public net.sf.ehcache.Status getStatus() {
        return null;
    }

    @Override
    public void dispose() throws CacheException {
        logger.info("缓存:");
    }

    @Override
    public void notifyCacheAdded(String s) {
        logger.info("缓存加入:",s);
        logger.info(cacheManager.getCache(s).toString());
    }

    @Override
    public void notifyCacheRemoved(String s) {
        logger.info("缓存清除：",s);
    }
}
